// 实现具体的迭代逻辑
// 例如假设是一个树的数据结构，具体如何迭代
// 使用广度优先遍历还是深度优先遍历

import { Iterator } from "./Interface";
import { User } from "./User";

export class UserIterator implements Iterator<User> {
  private collection: User[];
  private currentPosition = 0;

  constructor(collection: User[]) {
    this.collection = collection;
  }

  getNext(): User | undefined {
    if (!this.hasMore()) {
      return undefined;
    }
    return this.collection[this.currentPosition++];
  }

  hasMore(): boolean {
    return this.currentPosition < this.collection.length;
  }
}
